import EventCenter from "../../lib/EventCenter";
import MyDialogManager from "../../lib/MyDialogManager";
import { TipManager } from "../../lib/TipManager";
import EventEunm from "../data/EventEunm";
import PlayerData from "../data/PlayerData";

export default class LiveChangeScript extends Laya.Script{
    onEnable(){
        this.owner.getChildByName("jiaBtn").on(Laya.Event.CLICK,this,this.jiaClick);
        EventCenter.getIns().on(EventEunm.liveChange,this,this.fresh);
        this.fresh();
    }

    private fresh(){
        this.owner.getChildByName("numTxt")["text"]=PlayerData.getIns().live+"";
    }

    private jiaClick(){
        if(!PlayerData.getIns().isMaxLive()){
            MyDialogManager.getIns().sceneOpen("BuyLiveDialog.scene");
        }else{
            TipManager.ins.showMsgAlert("生命值已满");
        }
    }

    onDisable(){
        this.owner.getChildByName("jiaBtn").off(Laya.Event.CLICK,this,this.jiaClick);
        EventCenter.getIns().off(EventEunm.liveChange,this,this.fresh);
    }
}